<!DOCTYPE html>
<html xmlns:th="http://www.thymeleleaf.org" lang="cn">
<head>
    <meta charset="UTF-8">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
    <title>百年教育培训中心</title>
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <link rel="stylesheet" th:href="@{/static/css/activity-addr.css}">
    <script src="https://cdn.bootcss.com/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
    <div class="main">
        <!--<div class="title-box box">
            <p>百年教育培训中心</p>
        </div>-->
        <div class="banner-box box">
            <img src="../static/images/addr/addr.jpg" width="100%" height="100%"/>
        </div>
        <div class="form-box box">
            <p class="error" th:if="${type ne '1'}" th:text="${type eq '-1' ? '活动已结束' : (type eq '0' ? '您还未达到奖励要求，赶快邀请好友关注吧！' : '')}"></p>
            <div class="name-box box">
                <p>姓名</p>
                <input id="name" type="text" name="name" placeholder="请输入您的真实姓名"/>
            </div>
            <div class="phone-box box">
                <p>手机号码</p>
                <input id="mobile" type="text" name="phone" placeholder="请输入您的手机号码"/>
            </div>
            <div class="address-box box">
                <p>地址</p>
                <textarea name="address" id="address" placeholder="请输入您的详细地址，请仔细检查您的地址，否则会影响到奖品发放哦~"></textarea>
            </div>
            <div class="remark-box box">
                <p>备注</p>
                <textarea name="remark" id="remark" placeholder="请输入您想额外说的话"></textarea>
            </div>
            <div class="submit-box box">
                <input th:if="${type eq '1'}" id="submit" type="button" value="提交" th:disabled="${type eq '-1' || type eq '0'}"/>
            </div>
        </div>
        <input id="type" type="text" hidden="hidden" th:value="${type}" />
    </div>
</body>
<script>
    var type = document.getElementById("type");
    type = (type == null || type == undefined) ? "-1" : type;
    if(type.value == "-1") {
        alert("活动已结束");
        window.close();
    }
    if(type.value == "0") {
        alert("您还未达到奖励要求，赶快邀请好友关注吧！");
    }
    var submit = document.getElementById("submit");
    if(submit) {
        submit.onclick = function() {
            var type = document.getElementById("type");
            if(!type.value || type.value == "-1" || type.value == '0') {
                alert("保存失败");
            } else {
                $.ajax({
                    url: '/activity/saveAddress',
                    type: "POST",
                    data: {
                        name: $("#name").val(),
                        mobile: $("#mobile").val(),
                        address: $("#address").val(),
                        remark: $("#remark").val()
                    },
                    success: function(data) {
                        alert(data.message);
                    },
                    error: function() {
                        alert("保存失败");
                    }
                });
            }
        }
    }
</script>
</html>